package dk.mirasola.systemtraining.server.entity;

import com.google.appengine.api.users.User;
import com.googlecode.objectify.annotation.Unindexed;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.DistributionFilterGroup;
import dk.mirasola.systemtraining.server.DistributionFilterGroupFactory;

import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;

public class UserDistributionFilter {
    @Id
    Long id;

    User owner;

    String name;

    @Unindexed
    String description;

    @Unindexed
    String distributionFilterGroupStr;

    @Transient
    DistributionFilterGroup distributionFilterGroup;


    public UserDistributionFilter() {
    }

    public Long getId() {
        return id;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public DistributionFilterGroup getDistributionFilterGroup() {
        return distributionFilterGroup;
    }

    public void setDistributionFilterGroup(DistributionFilterGroup distributionFilterGroup) {
        this.distributionFilterGroup = distributionFilterGroup;
    }

    @PrePersist
    void distributionFilterGroupToString() {
        distributionFilterGroupStr = DistributionFilterGroupFactory.distributionFilterGroupToString(distributionFilterGroup);
    }

    @PostLoad
    void stringToDistributionFilterGroup() {
        distributionFilterGroup = DistributionFilterGroupFactory.stringToDistributionFilterGroup(distributionFilterGroupStr);
    }


}
